package com.agileboot.domain.airport.inspectionCheck.model;

import cn.hutool.core.bean.BeanUtil;
import com.agileboot.domain.airport.inspectionCheck.command.AddInspectionCheckCommand;
import com.agileboot.domain.airport.inspectionCheck.command.UpdateInspectionCheckCommand;
import com.agileboot.domain.airport.inspectionCheck.db.SirInspectionCheckEntity;
import com.agileboot.domain.airport.inspectionCheck.db.SirInspectionCheckService;
import com.agileboot.infrastructure.user.AuthenticationUtils;
import lombok.NoArgsConstructor;
import java.util.Date;

@NoArgsConstructor
public class InspectionCheckModel extends SirInspectionCheckEntity {

    private SirInspectionCheckService inspectionCheckService;

    public InspectionCheckModel(SirInspectionCheckService service) {
        this.inspectionCheckService = service;
    }

    public InspectionCheckModel(SirInspectionCheckEntity entity, SirInspectionCheckService service) {
        if (entity != null) {
            BeanUtil.copyProperties(entity, this);
        }
        this.inspectionCheckService = service;
    }

    public void loadFromAddCommand(AddInspectionCheckCommand addCommand) {
        if (addCommand != null) {
            BeanUtil.copyProperties(addCommand, this, "inspectionCheckId");
            // 自动赋值 creatorId
            this.setCreatorId(AuthenticationUtils.getUserId());
            // 自动赋值 createTime
            this.setCreateTime(new Date());
            // 自动赋值 deleted
            this.setDeleted(false);
        }
    }

    public void loadFromUpdateCommand(UpdateInspectionCheckCommand command) {
        if (command != null) {
            loadFromAddCommand(command);
        }
    }

    public void checkValid() {
        // 如需业务校验逻辑可添加，例如检查计划是否存在等
    }
}
